Skip to content

Add SegmentedControl component - #354

Open
georgerichmond wants to merge 9 commits into
mainfrom
add-toggle-button-group
Open

georgerichmond wants to merge 9 commits into
mainfrom
add-toggle-button-group

Conversation

@georgerichmond

@georgerichmond georgerichmond commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this change?

Adds SegmentedControl and SegmentedControlItem (@guardian/stand/SegmentedControl) for choosing one option from a small set of related options, such as the preview widths in HtmlPreview. It is built on React Aria's ToggleButtonGroup / ToggleButton.

API follows React Spectrum's SegmentedControl.

  • Selection is a single item key: selectedKey, defaultSelectedKey and onSelectionChange(key).
  • Once an item is selected, the selection cannot be cleared.
<SegmentedControl aria-label="Preview width" defaultSelectedKey={425}>
	<SegmentedControlItem id={320}>320</SegmentedControlItem>
	<SegmentedControlItem id={425}>425</SegmentedControlItem>
</SegmentedControl>

Scope: this PR includes only the Figma Small / Condensed text variant. XSmall, the default font width and icon variants can be added later. There is no disabled state because the Figma doesn't have one.

The component still needs design-system review, so it is marked as unverified.

Closes #352.

Question for reviewers

This PR only includes the Small / Condensed text variant, because that's all HtmlPreview needs right now. Should the other Figma variants (XSmall, the default font width and icons) be added in this PR, or in follow-up PRs when something needs them?

Adding them later won't break anything as long as Small / Condensed stays the default.

How to test

Check the SegmentedControl stories and docs in Storybook. Chromatic covers visual changes. In line with other components, there are no Playwright or unit tests.

Images

Figma design example:

Small condensed segmented control with its second option selected

Preview widths (default story):

Segmented control showing 320, 375, 425 and 650 with 425 selected

Selected positions:

Four segmented controls with 320, 375, 425 and 650 options, each selected in turn

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@georgerichmond
georgerichmond requested a review from a team as a code owner November 26, 2026 17:28
@georgerichmond georgerichmond added the run_chromatic Run the chromatic/storybook action. label Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Dependency Compatibility Matrix

React Emotion TypeScript RAC Typecheck Unit E2E Build Overall
17 11.11.4 5.0.4 1.14.0 ok ok ok ok ✅
17 11.11.4 5.0.4 1.21.1 ok ok ok ok ✅
17 11.11.4 5.9.3 1.14.0 ok ok ok ok ✅
17 11.11.4 5.9.3 1.21.1 ok ok ok ok ✅
17 11.11.4 6.0.2 1.14.0 ok ok ok ok ✅
17 11.11.4 6.0.2 1.21.1 ok ok ok ok ✅
17 11.14.0 5.0.4 1.14.0 ok ok ok ok ✅
17 11.14.0 5.0.4 1.21.1 ok ok ok ok ✅
17 11.14.0 5.9.3 1.14.0 ok ok ok ok ✅
17 11.14.0 5.9.3 1.21.1 ok ok ok ok ✅
17 11.14.0 6.0.2 1.14.0 ok ok ok ok ✅
17 11.14.0 6.0.2 1.21.1 ok ok ok ok ✅
18 11.11.4 5.0.4 1.14.0 ok ok ok ok ✅
18 11.11.4 5.0.4 1.21.1 ok ok ok ok ✅
18 11.11.4 5.9.3 1.14.0 ok ok ok ok ✅
18 11.11.4 5.9.3 1.21.1 ok ok ok ok ✅
18 11.11.4 6.0.2 1.14.0 ok ok ok ok ✅
18 11.11.4 6.0.2 1.21.1 ok ok ok ok ✅
18 11.14.0 5.0.4 1.14.0 ok ok ok ok ✅
18 11.14.0 5.0.4 1.21.1 ok ok ok ok ✅
18 11.14.0 5.9.3 1.14.0 ok ok ok ok ✅
18 11.14.0 5.9.3 1.21.1 ok ok ok ok ✅
18 11.14.0 6.0.2 1.14.0 ok ok ok ok ✅
18 11.14.0 6.0.2 1.21.1 ok ok ok ok ✅
19 11.14.0 5.0.4 1.14.0 ok ok ok ok ✅
19 11.14.0 5.0.4 1.21.1 ok ok ok ok ✅
19 11.14.0 5.9.3 1.14.0 ok ok ok ok ✅
19 11.14.0 5.9.3 1.21.1 ok ok ok ok ✅
19 11.14.0 6.0.2 1.14.0 ok ok ok ok ✅
19 11.14.0 6.0.2 1.21.1 ok ok ok ok ✅

Columns show granular outcomes for each dependency set: ok = passed, fail = failed, skip = upstream failure prevented running later stages. Overall: ✅ all passed, ⚠️ only skips (no hard fails), ❌ at least one fail.
Last updated: 2026-11-27T14:09:20.179Z (commit 7ea16a7)

@georgerichmond georgerichmond added the feature Departmental tracking: work on a new feature label Nov 26, 2026
Use the designer's segmented control terminology across the public API, package exports, tokens, documentation and examples. Match the Small / Condensed design and cover stable sizing when selection changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@georgerichmond georgerichmond changed the title Add ToggleButtonGroup component Add SegmentedControl component Nov 27, 2026
georgerichmond and others added 7 commits November 27, 2026 10:58
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Follow React Spectrum's SegmentedControl API: selectedKey,
  defaultSelectedKey and onSelectionChange(key); selection cannot be cleared
- Remove disabled state (not in Figma) and redundant selected typography tokens
- Use 2px focus outline offset, consistent with other components
- Trim stories, update docs, sandbox and changeset
- Point Figma link to the Design System file
- Remove Playwright spec and mock (visual coverage via Chromatic)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Like Tabs, the component relies on React Aria for selection and keyboard
behaviour, so drop the CSS/JS examples that duplicated styles.ts and
document the available design tokens instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stories, docs and sandbox now use the preview widths (320, 375, 425,
650px) that HtmlPreview offers, with numeric item ids.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Departmental tracking: work on a new feature run_chromatic Run the chromatic/storybook action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ToggleButtonGroup for segmented selection

1 participant